package com.push.web.controller.common;

import com.alibaba.fastjson.JSONObject;
import com.push.common.core.domain.AjaxResult;
import com.push.spider.utils.SpiderUtil;
import com.push.web.domain.BizArticle;
import com.push.web.service.IBizArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BizSpiderUtil
{
    @Autowired
    private IBizArticleService bizArticleService;

    /**
     *  爬虫获取指定数据源中的指定URL数据
     */
    @PostMapping("/common/callArticleCrawler")
    public AjaxResult callArticleCrawler(@RequestBody JSONObject requestJson){
        System.out.println("参数：" + requestJson.toString());
        Long articleId = requestJson.getLongValue("id");
        BizArticle bizArticle = bizArticleService.selectBizArticleById(articleId);
        String sourceId = bizArticle.getSourceId().toString();
        String url = bizArticle.getUrl();
        System.out.println("调用爬虫：" + sourceId + url);
        SpiderUtil.ClientSpider(sourceId, url);
        return AjaxResult.success();
    }
}
